package cn.kgc.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/10/8
 * @description /hello2
 */
public class HelloServlet2 extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取请求方式  get  post
        String method = req.getMethod();
        System.out.println("hello javaWeb " + method);


        // 课程信息
        List<String> courses = Arrays.asList("Java", "Html", "Css");
        // 响应数据到前端页面   响应对象
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();

        // 将课程信息以无序列表的形式展示
        writer.write("<ul>");
        courses.forEach(course-> writer.write(" <li > "+course+" </li >"));
        writer.write(" </ul>");
        writer.close();

    }
}
